import grpc
import time
from google.protobuf import empty_pb2
from api.cgvmagent.v1 import vm_service_pb2, vm_service_pb2_grpc


def main():
    # 连接到gRPC服务器
    channel = grpc.insecure_channel('10.141.194.106:30114')
    stub = vm_service_pb2_grpc.VMServiceStub(channel)

    ids1 = [3359, 3324, 3350]
    for id_ in ids1:
        request = vm_service_pb2.UpdateVMRequest(
            id=id_,
            vm_game_info=vm_service_pb2.VMGameInfo(
                channel=0,
                vm_games=[
                    vm_service_pb2.VMGame(
                        game_id=35367,
                        game_set_versions=[2648]
                    )
                ]
            )
        )

        start_time = time.time()
        # 调用UpdateVM方法
        try:
            response = stub.UpdateVM(request)
            elapsed = time.time() - start_time
            print(f"UpdateVM for ID {id_} executed in {elapsed:.3f}s")
        except grpc.RpcError as e:
            print(f"RPC failed for ID {id_}: {e.code()}")


if __name__ == '__main__':
    main()